package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.Sign;
import cn.wolfcode.trip.base.query.SignQueryObject;
import cn.wolfcode.trip.base.service.ISignService;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/days")
public class SignController {
    @Autowired
    private ISignService signService;
    @PostMapping
    public JSONResult save(Sign entity,SignQueryObject qo){
        JSONResult result=new JSONResult();
        if(getSign(qo).contains(entity.getDate())){
            result.mark("亲,您今天已签到");
        }
        signService.saveOrUpdate(entity);
        return result;
    }

    @GetMapping
    public List getSign(SignQueryObject qo){
        List signs = signService.querySigns(qo);
        return signs;
    }

    @GetMapping("/{user.id}/state")
    public Integer getState(Sign entity){
        Integer state = signService.queryState(entity);
        return state;
    }


    @GetMapping("/{months}")
    public Object getDays(SignQueryObject qo){
        Integer count = signService.queryCount(qo);
        return count;
    }
    @PutMapping("/{user.id}")
    public JSONResult updatePoint(Sign entity){

        JSONResult result = signService.updataPoint(entity);

        return result;
    }
    //查询用户积分用来回显profiles.html页面
    @GetMapping("points")
    public Integer getUserPoint(Long userId){
        return signService.getUserPoint(userId);
    }
}
